package com.basic.seleniumstudy.demos.selenium;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;



public class TryTest {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "D:\\developTools\\environment\\jdk\\jdk1.8\\bin\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.mysteel.com/zsjs/");
        WebDriverWait wait = new WebDriverWait(driver, 10);
        // 等待页面加载完成("哔哩哔哩"表示页面完全加载完成的标志，也可以是别的)
//        wait.until(d -> d.getTitle().contains("哔哩哔哩"));
        wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")));
        String pageSource = driver.getPageSource();

        JavascriptExecutor javascriptExecutor= (JavascriptExecutor) driver;
        String pageSource1 = (String) javascriptExecutor.executeScript("return document.documentElement.outerHTML;");
        Document doc = Jsoup.parse(pageSource1);
        Elements logo = doc.select(".logo");
        for (Element element : logo) {
            Element child = element.child(0);
            System.out.println(child.attr("title"));
        }

        driver.quit();
    }
}
